package fair.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import fair.dao.MemberDao;
import fair.dao.OrderDao;
import fair.service.ReportService;
import fair.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author fair_wu
 * @version v1.0
 * @package fair.service.impl
 * @date 2021-02-09 下午 16:43
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
    @Override
    public Map<String, Object> getBusinessReportData() {
        try {
            Map<String, Object> map = new HashMap<>();
            String today = DateUtils.parseDate2String(DateUtils.getToday());
            String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
            String firstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
            //日期
            map.put("reportDate", today);
            //本日新增会员数
            Integer todayNewMember = memberDao.findMemberCountByDate(today);
            map.put("todayNewMember", todayNewMember);
            //总会员数
            Integer totalMember = memberDao.findTotalMemberCount();
            map.put("totalMember", totalMember);
            //本周新增会员数
            Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(monday);
            map.put("thisWeekNewMember", thisWeekNewMember);
            //本月新增会员数
            Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay);
            map.put("thisMonthNewMember", thisMonthNewMember);
            //金融预约数
            Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
            map.put("todayOrderNumber", todayOrderNumber);
            //今天就诊数
            Integer todayVisitsNumber = orderDao.findVisitCountByDate(today);
            map.put("todayVisitsNumber", todayVisitsNumber);
            //本周预约数
            Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(monday);
            map.put("thisWeekOrderNumber", thisWeekOrderNumber);
            //本周就诊数
            Integer thisWeekVisitsNumber = orderDao.findVisitCountAfterDate(monday);
            map.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
            //本月预约数
            Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay);
            map.put("thisMonthOrderNumber", thisMonthOrderNumber);
            //本月就诊数
            Integer thisMonthVisitsNumber = orderDao.findVisitCountAfterDate(firstDay);
            map.put("thisMonthVisitsNumber", thisMonthVisitsNumber);
            //热门套餐
            List<Map<String, Object>> hotSetmeal = orderDao.findHotSetmeal();
            map.put("hotSetmeal", hotSetmeal);
            return map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
